package cn.com.dcsgo.design.pattern.builder.car;

/**
 * 汽车各个生产步骤的具体实现
 *
 * @author Dcsgo
 * @since 21/7/2025 上午 9:13
 */

public class CarBuilder implements Builder {
    /**
     * 生产的汽车
     */
    private Car result;

    @Override
    public void reset() {
        result = new Car();
    }

    @Override
    public void setSeats(int number) {

    }


    @Override
    public void setEngine(Engine engine) {
        result.setEngine(engine);
    }

    @Override
    public void setTripComputer(String tripComputer) {
        result.setTripComputer(tripComputer);
    }

    @Override
    public void setGps(String gps) {
        result.setGps(gps);
    }

    /**
     * 获取所生产的汽车
     * 具体的生成器返回具体的类对象
     *
     * @return 所生产的汽车
     */
    public Car getResult() {
        if (result == null) {
            throw new IllegalStateException("汽车尚未生产完成");
        }
        Car builtCar = result;
        result = null;
        return builtCar;
    }
}
